import { NODE_ID_LABEL_MAP2 } from '../common/constants';
import initServerInstance from '../server/initServerInstance';

if (require.main === module) {
	(async () => {
		const server = await initServerInstance({
			loggerConfig: {
				name: 'upgrade',
				alwaysCreate: true,
			},
		});

		for await (const record of server.app.model.Job.find()) {
			record.httpSettings = record.httpSettings.map(x => {
				const s = x.toObject();
				s.collect.area = s.collect.area.filter(x => NODE_ID_LABEL_MAP2[x]);
				return s;
			});
			record.pingSettings = record.pingSettings.map(x => {
				const s = x.toObject();
				s.collect.area = s.collect.area.filter(x => NODE_ID_LABEL_MAP2[x]);
				return s;
			});
			await record.save().catch(error => console.log(error));
		}

		process.exit();
	})();
}
